package com.sms.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sms.dao.IFilterStrDAO;
import com.sms.po.FilterStr;


/**
 * @author 20111009 by cxh
 */
public class FilterStrDAO extends HibernateDaoSupport implements IFilterStrDAO {
	private static final Log log = LogFactory.getLog(FilterStrDAO.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<FilterStr> showAllFilterStr() {
		log.debug("finding all FilterStr instances");
		try{
			return super.getHibernateTemplate().find("from FilterStr");
		}catch(RuntimeException e){
			log.debug("finding all failed:",e);
			throw e;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FilterStr> showAllFilterStrByPage(DetachedCriteria criteria, int start,int limit) {
		log.debug("finding all FilterStr by pages");
		try{
			return super.getHibernateTemplate().findByCriteria(
					criteria, start, limit);
		}catch(RuntimeException e){
			log.debug("finding all FilterStr failed:",e);
			throw e;
		}
	}

	@Override
	public int getAllFilterStrCount(DetachedCriteria criteria) {
		return super.getHibernateTemplate().findByCriteria(criteria).size();
	}

	@Override
	public boolean addFilterStr(FilterStr fs) {
		log.debug("add FilterStr instance...");
		try{
			log.debug("add FilterStr instance success");
			this.getHibernateTemplate().save(fs);
			return true;
		}catch(RuntimeException e){
			log.debug("add FilterStr instance failed:",e);
			throw e;
		}
	}

	@Override
	public boolean removeFilterStr(FilterStr fs) {
		log.debug("remove FilterStr instance...");
		try{
			
			this.getHibernateTemplate().delete(fs);
			return true;
		}catch(RuntimeException e){
			log.debug("remove FilterStr instance failed:",e);
			throw e;
		}
	}
	
	
	public boolean updateFilterStr(FilterStr fs) {
		log.debug("update FilterStr instance...");
		try{
			this.getHibernateTemplate().update(fs);
			return true;
		}catch(RuntimeException e){
			log.debug("update FilterStr instance failed:",e);
			throw e;
		}
	}

}
